import {getGoodsList,getSort} from 'api/api';
export default{
    state:{
        goodsList:[],
        total:0,
        trademarkList:[],
        attrsList:[],
        sortTypes:[]
    },
    mutations:{
        getGoodsList(state,{total,goodsList,trademarkList,attrsList}){
            state.goodsList=goodsList
            state.total=total
            state.trademarkList=trademarkList
            state.attrsList=attrsList
        },
        getSortTypes(state,sortTypes){
            state.sortTypes=sortTypes
        }
    },
    actions:{
        async getGoodsList(store,options){
           try{
            const {code,data} = await getGoodsList(options)
            if(code===200){
                store.commit('getGoodsList',{
                    goodsList:data.goodsList,
                    total:data.total,
                    trademarkList:data.trademarkList,
                    attrsList:data.attrsList
                })
                // console.log('进入');
                
                await store.dispatch('getSort')
            }
            // console.log(data);
            return {code,data}
           }catch(e){
               return Promise.reject(e)
           }
        },
        async getSort(store){
            try{
                // console.log('getSort',getSort);
                
                const {code,data} = await getSort()
            
                if(code===200){
                    store.commit('getSortTypes',data)
                }
                return {code,data}
            }catch(e){
               return  Promise.reject(e)
            }
        }
    },
    getters:{}
}